package cn.xaut.XAUT迎春杯预热;

import java.util.Scanner;

/**
 * C - 二维数组转置
 */
public class demoC {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int m = input.nextInt();
        System.out.println(m + " " + n);
        int[][] grid = new int[n][m];   // 原数组
        
        // 初始化
        for (int i = 0; i < n; i++) 
            for (int j = 0; j < m; j++) 
                grid[i][j] = input.nextInt();

        for (int j = 0; j < m; j++) {
            for (int i = 0; i < n; i++) 
                System.out.print(grid[i][j] + " ");
            System.out.println();
        }
    }
}
